import * as React from "react";
import Modal from "antd/es/modal/Modal";
import {Button, Card, Col, Form, Input, InputNumber, notification, Row} from "antd";
import {PlusOutlined, UserOutlined} from "@ant-design/icons";
import {createKey, disableOwnKey, updateKey, updateOwnKey} from "../../requests/KeyManageRequest";
import {disableRole} from "../../requests/RoleManageRequest";


class DisableRoleModal extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            isModalVisible: false,
            formRef: React.createRef(),
            isOwn: this.props.isOwn
        };
        this.props.onRef(this)
    }

    showModal = () => {
        this.setState({
            isModalVisible: true
        })
    };

    handleCancel = () => {
        this.setState({
            isModalVisible: false
        })
    };

    handleOk = () => {

        if (!this.props.roleName) {
            notification.error({message: "禁用角色失败", description: "请在表格中选择角色之后进行禁用！"});
            return
        }
        console.log("Begin to disable role with params:" + JSON.stringify(this.props.roleName))
        disableRole(this.props.roleName).then(edpRole => {
            notification.info({message: "禁用角色成功", description: "禁用角色" + edpRole.result.roleName + "成功"});
        })

        this.setState({
            isModalVisible: false
        })

    };

    render = () => {
        return (
            <Modal title="禁用角色" visible={this.state.isModalVisible} onOk={this.handleOk} onCancel={this.handleCancel}>
                <p>确认禁用角色{this.props.roleName}</p>
            </Modal>
        );
    }
}

export default DisableRoleModal